package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.UserActiveMessaging;
import com.happy.cat.project.system.service.IUserActiveMessagingService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 用户动态消息Controller
 *
 * @author verne
 * @date 2020-08-16
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userActiveMessaging" )
@Api("用户动态消息 API")
public class UserActiveMessagingController extends BaseController {

    private final IUserActiveMessagingService iUserActiveMessagingService;

    /**
     * 查询用户动态消息列表
     */
    @ApiOperation(value = "查询用户动态消息列表",notes = "查询用户动态消息列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userActiveMessaging:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserActiveMessaging userActiveMessaging)
    {
        startPage();
        LambdaQueryWrapper<UserActiveMessaging> lqw = new LambdaQueryWrapper<UserActiveMessaging>();
        if (StringUtils.isNotBlank(userActiveMessaging.getContent())){
            lqw.eq(UserActiveMessaging::getContent ,userActiveMessaging.getContent());
        }
        if (userActiveMessaging.getType() != null){
            lqw.eq(UserActiveMessaging::getType ,userActiveMessaging.getType());
        }
        if (userActiveMessaging.getAccountId() != null){
            lqw.eq(UserActiveMessaging::getAccountId ,userActiveMessaging.getAccountId());
        }
        if (userActiveMessaging.getSendTime() != null){
            lqw.eq(UserActiveMessaging::getSendTime ,userActiveMessaging.getSendTime());
        }
        if (StringUtils.isNotBlank(userActiveMessaging.getPhotoMessagePath())){
            lqw.eq(UserActiveMessaging::getPhotoMessagePath ,userActiveMessaging.getPhotoMessagePath());
        }
        if (userActiveMessaging.getCommentCount() != null){
            lqw.eq(UserActiveMessaging::getCommentCount ,userActiveMessaging.getCommentCount());
        }
        if (userActiveMessaging.getLikeCount() != null){
            lqw.eq(UserActiveMessaging::getLikeCount ,userActiveMessaging.getLikeCount());
        }
        if (userActiveMessaging.getParentId() != null){
            lqw.eq(UserActiveMessaging::getParentId ,userActiveMessaging.getParentId());
        }
        if (StringUtils.isNotBlank(userActiveMessaging.getAdress())){
            lqw.eq(UserActiveMessaging::getAdress ,userActiveMessaging.getAdress());
        }
        if (userActiveMessaging.getApplyTime() != null){
            lqw.eq(UserActiveMessaging::getApplyTime ,userActiveMessaging.getApplyTime());
        }
        if (StringUtils.isNotBlank(userActiveMessaging.getApplyBy())){
            lqw.eq(UserActiveMessaging::getApplyBy ,userActiveMessaging.getApplyBy());
        }
        if (StringUtils.isNotBlank(userActiveMessaging.getApplyText())){
            lqw.eq(UserActiveMessaging::getApplyText ,userActiveMessaging.getApplyText());
        }
        if (userActiveMessaging.getStatus() != null){
            lqw.eq(UserActiveMessaging::getStatus ,userActiveMessaging.getStatus());
        }
        List<UserActiveMessaging> list = iUserActiveMessagingService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户动态消息列表
     */
    @ApiOperation(value = "导出用户动态消息列表",notes = "导出用户动态消息列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userActiveMessaging:export')" )
    @Log(title = "用户动态消息" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserActiveMessaging userActiveMessaging) {
        LambdaQueryWrapper<UserActiveMessaging> lqw = new LambdaQueryWrapper<UserActiveMessaging>(userActiveMessaging);
        List<UserActiveMessaging> list = iUserActiveMessagingService.list(lqw);
        ExcelUtil<UserActiveMessaging> util = new ExcelUtil<UserActiveMessaging>(UserActiveMessaging. class);
        return util.exportExcel(list, "userActiveMessaging" );
    }

    /**
     * 获取用户动态消息详细信息
     */
    @ApiOperation(value = "获取用户动态消息详细信息",notes = "获取用户动态消息详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userActiveMessaging:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserActiveMessagingService.getById(id));
    }

    /**
     * 新增用户动态消息
     */
    @ApiOperation(value = "新增用户动态消息",notes = "新增用户动态消息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userActiveMessaging:add')" )
    @Log(title = "用户动态消息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserActiveMessaging userActiveMessaging) {
        return toAjax(iUserActiveMessagingService.save(userActiveMessaging) ? 1 : 0);
    }

    /**
     * 修改用户动态消息
     */
    @ApiOperation(value = "修改用户动态消息",notes = "修改用户动态消息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userActiveMessaging:edit')" )
    @Log(title = "用户动态消息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserActiveMessaging userActiveMessaging) {
        return toAjax(iUserActiveMessagingService.updateById(userActiveMessaging) ? 1 : 0);
    }

    /**
     * 删除用户动态消息
     */
    @ApiOperation(value = "删除用户动态消息",notes = "删除用户动态消息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userActiveMessaging:remove')" )
    @Log(title = "用户动态消息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserActiveMessagingService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
